package com.aaa.mrcai.service.impl;

import cn.hutool.core.date.DateUtil;
import com.aaa.mrcai.mapper.OrderAddMapper;
import com.aaa.mrcai.pojo.entity.AdminSo;
import com.aaa.mrcai.pojo.entity.Test;
import com.aaa.mrcai.pojo.entity.UserInfo;
import com.aaa.mrcai.pojo.vo.ShopSoVO;
import com.aaa.mrcai.service.OrderAddService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletContext;


/**
 * @ Author: Lining
 * @ Date: 2021/12/20 17:08
 */
@Service
public class OrderAddServiceImpl implements OrderAddService {


    @Autowired
    private OrderAddMapper orderAddMapper;

    @Autowired
    private ServletContext servletContext;

    @Override
    public int addPendingOrder(Test test, ShopSoVO shopSoVO) {

        //取出id看是否为正确的订单号
        String soid = test.getSoid();
        System.out.println("OrderADDServiceImpl的soid:"+soid);

        //给test设置uid为当前登录的id
        UserInfo user = (UserInfo) servletContext.getAttribute("user");
        Integer uid = user.getId();
        test.setUid(uid);
        System.out.println("uid:"+uid);

        //给test设置当前时间
        String today = DateUtil.now();
        test.setOrderdate(today);
        System.out.println(today);
        int i = orderAddMapper.addPendingOrder(test);
        shopSoVO.setOid(test.getId());
        servletContext.setAttribute("shopVO",shopSoVO);
        System.out.println("存入的shopVOid"+shopSoVO);
        int i1 = orderAddMapper.addOneGoodInOrder(shopSoVO);
        return i;
    }

    @Override
    public int updataOrder(Test liushui) {
        ShopSoVO shopVO = (ShopSoVO) servletContext.getAttribute("shopVO");
        Integer id = shopVO.getId();
        System.out.println("输出的shopVo"+shopVO);
        System.out.println("商品的id"+id);
        orderAddMapper.updateNum(id);
        return orderAddMapper.updataOrder(liushui);
    }

}
